import "package:flutter/material.dart";
import '../style/color.dart';
import '../route/delegate.dart';

// 构造通用Appbar方法
AppBar buildCommonAppbar(BuildContext ctx,
    {String leftText = '',
    String rightText = '',
    VoidCallback rightTextTrigger,
    @required bool needBackButton}) {
  // 构建文字按钮方法
  final _buildTextButton = () {
    return TextButton(
        onPressed: rightTextTrigger,
        style: ButtonStyle(overlayColor: GreyMaterialColor()),
        child: Text(
          rightText,
          style: TextStyle(color: grayTextColor, fontSize: 18),
        ));
  };
  return AppBar(
    centerTitle: false,
    titleSpacing: 0,
    leading: needBackButton
        ? BackButton(
            color: Colors.black,
            onPressed: () => BiliRouterDelegate.of(ctx).pop())
        : null,
    title: Text(needBackButton ? leftText : '',
        style: TextStyle(fontSize: 18, color: Colors.black)),
    actions: [
      Padding(
        padding: EdgeInsets.symmetric(
          horizontal: 15,
        ),
        child: _buildTextButton(),
      )
    ],
  );
}
